#include <FL/fl_ask.h>

#include <math.h>

#include "ScissorUI.h"
#include "ScissorDoc.h"

Fl_Menu_Item ScissorUI::menuitems[] = {
	{ "&File",		0, 0, 0, FL_SUBMENU },
		{ "&Load Image...",	FL_ALT + 'l', (Fl_Callback *)ScissorUI::cb_load_image },
/*		{ "&Save Image...",	FL_ALT + 's', (Fl_Callback *)ImpressionistUI::cb_save_image },
		{ "&Clear Canvas", FL_ALT + 'c', (Fl_Callback *)ImpressionistUI::cb_clear_canvas, 0, FL_MENU_DIVIDER },
		
		{ "&Quit",			FL_ALT + 'q', (Fl_Callback *)ImpressionistUI::cb_exit },
*/		{ 0 },
/*	{"&Tool",		0, 0, 0, FL_SUBMENU },
		{ "Scisso&r", FL_ALT + 'r', (Fl_Callback *)ImpressionistUI::cb_scissor },
		{ "Zoom in", FL_CTRL+'+', (Fl_Callback *)ImpressionistUI::cb_zoomin },
		{ "Zoom out", FL_CTRL+'-', (Fl_Callback *)ImpressionistUI::cb_zoomout },
		{ 0 },

	{ "&Help",		0, 0, 0, FL_SUBMENU },
		{ "&About",	FL_ALT + 'a', (Fl_Callback *)ImpressionistUI::cb_about },
		{ 0 },
*/
	{ 0 }
};

ScissorUI::ScissorUI() {
		// Create the main window
	m_mainWindow = new Fl_Window(600, 300, "Impressionist");
		m_mainWindow->user_data((void*)(this));	// record self to be used by static callback functions
		// install menu bar
		//m_menubar = new Fl_Menu_Bar(0, 0, 600, 25);
		//m_menubar->menu(menuitems);

		// Create a group that will hold two sub windows inside the main
		// window
		//Fl_Group* group = new Fl_Group(0, 25, 600, 275);

			// install paint view window
			//m_paintView = new PaintView(300, 25, 300, 275, "This is the paint view");//0jon
			//m_paintView->box(FL_DOWN_FRAME);

			// install original view window
			m_origView = new OriginalView(0, 25, 300, 275, "This is the orig view");//300jon
			delete m_origView;
			//m_origView->box(FL_DOWN_FRAME);
			//m_origView->deactivate();

		//group->end();
		//Fl_Group::current()->resizable(group);
    m_mainWindow->end();
	printf("here\n");
}

void ScissorUI::show() {
	m_mainWindow->show();
	m_origView->show();
}

void ScissorUI::setDocument(ScissorDoc* doc) {
	m_pDoc = doc;
}

ScissorDoc* ScissorUI::getDocument() {
	return m_pDoc;
}

ScissorUI*	ScissorUI::whoami(Fl_Menu_* o) {
	return ((ScissorUI*)(o->parent()->user_data()) );
}

// Callback functions here
void ScissorUI::cb_load_image(Fl_Menu_* o, void* v) {
	ScissorDoc *pDoc=whoami(o)->getDocument();

	char* newfile = fl_file_chooser("Open File?", "*.bmp", pDoc->getImageName() );
	if (newfile != NULL) {
		pDoc->loadImage(newfile);
	}
}
